var loginObj = {
    init: function() {
        this.hideLoginBox();
        this.getVcode();
        this.login();
    },
    //隐藏登录框
    hideLoginBox: function() {
        $(".n_l_dele").bind("click", function() {
            $(".normallogin").hide();
            $(".layerbox").hide();
        })
    },
    getVcode: function() {
        var me = this;
        $(".checkboxtxt1").bind("click", function() {
            var urlStr = magic_config.urlPrefix + 'UserService/setCheckcode';
            var userid = $(".n_l_mob").val();
            $(".n_l_errtip").html("");
            if (userid == "") {
                $(".n_l_errtip").html("请输入手机号");
                return;
            }
            var dataObj = {
                userId: userid
            }
            $.ajax({
                url: urlStr,
                type: 'get',
                data: dataObj,
                dataType: 'json',
                success: function(res) {
                    var nCode = res.return.nCode;
                    if (nCode === 0) {
                        $(".checkboxtxt1").hide();
                        $(".checkboxtxt2").show();
                        me.countDown();
                    } else {
                        $(".n_l_errtip").html(res.return.strText);
                    }
                },
                error: function(res) {
                    console.log("数据请求失败，前到后");
                }
            });
        })
    },
    //倒计时
    countDown: function() {
        var time = 60;
        var interval = setInterval(function() {
            if (time <= 0) {
                time = 60;
                $(".checkboxtxt2").html(time + 's');
                $(".checkboxtxt1").show();
                $(".checkboxtxt2").hide();
                clearInterval(interval);

            } else {
                time -= 1;
                $(".checkboxtxt2").html(time + 's');
            }
        }, 1000);
    },
    login: function() {
        var me = this;
        $(".n_l_btn").bind("click", function() {
            var urlStr = magic_config.urlPrefix + 'UserService/userreglogin';
            $(".n_l_errtip").html("");
            var userid = $(".n_l_mob").val();
            var vcode = $(".n_l_checkcode ").val();
            console.log(userid);
            if (userid == "") {
                $(".n_l_errtip").html("请输入手机号");
                return;
            }
            if (vcode == "") {
                $(".n_l_errtip").html("请输入验证码");
                return;
            }
            var dataObj = {
                userId: userid,
                checkCode: vcode,
            }
            console.log(dataObj);
            $.ajax({
                url: urlStr,
                type: 'get',
                data: dataObj,
                dataType: 'json',
                success: function(res) {
                    var nCode = res.return.nCode;
                    if (nCode === 0) {
                        localStorage.setItem("mobile_userid", res.response.userId);
                        sessionStorage.setItem("mobile", res.response.userId);
                        //location.href = './checkMarket.html';
                        $.cookie("userid", res.response.userId, {　　
                            path: "/",
                            expires: 7
                        })
                        $(".normallogin").hide();
                        $(".layerbox").hide();
                        location.replace("./pay.html");
                    } else {
                        $(".n_l_errtip").html(res.return.strText);
                        console.log("数据请求失败，后到前");
                    }
                },
                error: function(res) {
                    console.log("数据请求失败，前到后");
                }
            });
        })
    },
};
loginObj.init();